package com.example.nfcproducttracing;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class ProductFragment extends Fragment {
	
	Product product;
    int px;
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    	setRetainInstance(true);
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.product, container, false);
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState)
    {
		super.onActivityCreated(savedInstanceState);	
    }
    
    @Override
    public void onResume()
    {
        super.onResume();
        
        if (product == null)
        {   
        	product = ((ProductActivity) getActivity()).readNDEFRecord(((ProductActivity) getActivity()).getIntent());
        }
        
        Button productHeader = (Button) getView().findViewById(R.id.ProductHeader);
        TextView productType = (TextView) getView().findViewById(R.id.ProductType);
        TextView productOrigin = (TextView) getView().findViewById(R.id.ProductOrigin);
        TextView productionDate = (TextView) getView().findViewById(R.id.ProductionDate);
        TextView productionMethod = (TextView) getView().findViewById(R.id.ProductionMethod);
        TextView productSeed = (TextView) getView().findViewById(R.id.ProductSeed);
        
        Button producerHeader = (Button) getView().findViewById(R.id.ProducerHeader);
        TextView producerAddress1 = (TextView) getView().findViewById(R.id.ProducerAddress1);
        TextView producerAddress2 = (TextView) getView().findViewById(R.id.ProducerAddress2);
        TextView producerEmail = (TextView) getView().findViewById(R.id.ProducerEmail);
        TextView producerTelephone = (TextView) getView().findViewById(R.id.ProducerTelephone);
        
        productHeader.setText(product.name);
        productType.setText("Type : " + product.type);
        productOrigin.setText("Origin : " + product.origin);
        productionDate.setText("Production Date : " + product.productionDate);
        productionMethod.setText("Production Method : " + product.productionMethod);
        productSeed.setText("Product Seed : " + product.seed);

        producerHeader.setText(product.producer.name);
        producerAddress1.setText( product.producer.address + ", " + product.producer.postCode);
        producerAddress2.setText( product.producer.city + ", " + product.producer.country);
        producerEmail.setText("E-mail : " + product.producer.email);
        producerTelephone.setText("Telephone : " + product.producer.telephone);
    }
}